package com.wqmei.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wqmei.dao.PersonMapper;
import com.wqmei.model.Person;
import com.wqmei.service.IPersonService;

@Service
public class PersonServiceImpl implements IPersonService {
	@Autowired
	private PersonMapper personMapper;

	public Person selectPerson(int id) {
		Person person = personMapper.selectByPrimaryKey(id);
		return person;
	}

	public List<Person> selectPersonByName(String name) {
		List<Person> person = personMapper.selectByName(name);
		return person;
	}
	
	/**
	 * 通过电话号码模糊查找
	 */
	public List<Person> selectPersonByNumber(String number) {
		List<Person> person = personMapper.selectByNumber(number);
		return person;
	}

	public List<Person> selectAllPeople() {
		List<Person> person = personMapper.selectAll();
		return person;
	}

	public int deletePerson(int id) {
		int count = personMapper.deletePerson(id);
		return count;
	}

	public int updatePerson(Person person) {
		int count=0;
		/*Person person2 = personMapper.selectByPrimaryKey(person.getId());
		if(person2!=null){
			if(!person.getNumber().equals(person2.getNumber())){
			if(!person2.getNumber().equals(person.getNumber())){
				return count;
			}}
			
		}*/
		count = personMapper.updatePerson(person);
		return count;
	}

	public int insertPerson(Person person) {
		int count=0;
		Person person2 = personMapper.selectByWholeNumber(person.getNumber());
		if(person2==null){
		count = personMapper.insertPerson(person);}
		return count;
	}

}
